
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<style>
    #selectPODiv .modal-dialog{
        margin: 80px auto;
    }
    #selectPODiv .form-group select, #selectPODiv .form-group input {
        width: calc(100vw / 2 - 400px);
    }
    .btn-warning.btn-outline {
        color: #fff;
    }
    .btn-submit{
        background: #2c74fa;
        margin-left: 20px;
        border: none;
        color: #fff;
    }
</style>

<div class="modal" id="selectPODiv" tabindex="-1" role="dialog" aria-hidden="true" style="width: auto;">

    <div class="modal-dialog modal-lg" role="document">

        <div class="modal-content animated bounceInRight">

            <div class="modal-header">
                <h4 class="modal-title">物料选择</h4>
                <button type="button" class="close" data-dismiss="modal"
                        aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <div class="modal-body" style="padding-bottom: 20px; padding-top: 5px;">

                <jsp:include page="../search/soSearch.jsp"></jsp:include>

                <div class="table-responsive">

                    <div class="col-sm-12 text-right" style="padding-right: 0px;">
                        <button id="searchConfirmButton" type="button" class="btn btn-success btn-sm" style="margin-bottom: 5px; display: none;">查询</button>
                        <button id="searchButton" class="btn btn-default btn-sm" type="button" style="margin-bottom: 5px;"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
                    </div>

                    <table class="table table-striped table-hover table-bordered border-top">
                        <thead>
                        <tr>
                            <th></th>
                            <th>名称</th>
                            <th>型号</th>
                            <th>编码</th>
                            <th>品牌</th>
                            <th>单位</th>
                            <th>库存数量</th>
                        </tr>
                        </thead>
                        <tbody>

                        <c:forEach items="${requestScope.deliveryNoteHeadList}" var="data" varStatus="status">
                            <tr>
                                <td><input type="checkbox" class="i-checks" name="input[]"></td>
                                <td class="materialName">${data.materialName}</td>
                                <td class="standard">${data.standard}</td>
                                <td class="material_code">${data.material_code}</td>
                                <td class="brand">${data.brand}</td>
                                <td class="standardUnit">${data.standardUnit}</td>
                                <td class="numCount">${data.numCount}</td>

                            </tr>
                        </c:forEach>

                        </tbody>
                        <tfoot>
                        <%-- 导入页码 --%>
                        <jsp:include page="../../common/popPages.jsp"></jsp:include>
                        </tfoot>
                    </table>
                </div>
                <div class="col-md-12">
                    <div class="form-group row m-b-none">
                        <div class="col-sm-10 col-sm-offset-2 text-right">
                            <button class="btn btn-white btn-lg" type="button" data-dismiss="modal">返回</button>
                            &nbsp;
                            <button id="selectButton" class="btn btn-submit" data-style="expand-right">
                                确定
                            </button>
                        </div>
                    </div>
                </div>

            </div>

        </div>

    </div>

</div>



<div  class="modal " id="outPutDiv" tabindex="-1" role="dialog" >
    <div class="modal-dialog" role="document" style="margin-top:50px;">
        <div class="modal-content" style="padding: 0 20px">
            <div class="modal-header">
                <h4 class="modal-title" id="ora_modal_title"></h4>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="close()"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <c:import url="/web/mdFinanceSubject/getMdFinanceSubjectTree" charEncoding="utf-8"></c:import>
            </div>
        </div>
    </div>
</div>

<!--选择下一步审批人模态框-->
<div id="approverSelectOutput" class="modal comTreemodal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content" >
            <div class="modal-body">
                <div class="row">
                    <div class="col-sm-6">
                        <%--<c:import url="/web/hrDepartment/getHrDepartmentTreeReadOnly" charEncoding="utf-8"></c:import>--%>
                        <div class="ibox ">
                            <div class="ibox-content border-bottom">
                                <div class="input-group col-sm-12">
                                    <div class="input-group-addon bg-info">
                                        <i class="fa fa-search"></i>
                                    </div>
                                    <input type="text" class="form-control" id="searchTree1" placeholder="输入查询条件...">
                                </div>
                                <div class="hr-line-dashed"></div>
                                <div id="jstree_div_output" style="overflow: auto;"></div>
                            </div>
                        </div>
                    </div>
                    <%--<div id="relateListDiv" class="col-sm-6"></div>--%>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="submitSelect" onclick="submitSelect2()">确定</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        //初始化checkbox
        $('.i-checks').iCheck({
            checkboxClass : 'icheckbox_square-green',
            radioClass : 'iradio_square-green',
        });



       /* $("#costSubject").on("click",function(){
            $('#approverSelect').modal('show');
            $('.show').removeClass("modal-backdrop");
        });*/

        //checkbox选中效果
        $("tr").click(function(){
            if($(this).find(".i-checks").prop("checked")){
                $(this).find(".i-checks").iCheck('uncheck');
            }else{
                $(".i-checks").iCheck('uncheck');
                $(this).find(".i-checks").iCheck('check');
            }

        });

        //查询条件
     /*   $("#searchButton").click(function() {
            if ($("#searchDiv").css("display") == "none") {
                $("#searchDiv").show();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
                $("#searchButton").addClass("btn-outline btn-warning");
                $("#searchButton").blur();
                $("#searchConfirmButton").show();
            } else {
                $("#searchDiv").hide();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
                $("#searchButton").removeClass("btn-outline btn-warning");
                $("#searchButton").blur();
                $("#searchConfirmButton").hiden();
            }
        });*/

        //确认按钮
        $("#selectButton").click(function(){

            var selectFlag = "N"
            var materialName =  "";
            var standard = "";
            var material_code = "";
            var brand = "";
            var standardUnit = "";
            var numCount = "";

            $('.i-checks').each(function(){
                if($(this).prop("checked")){
                    selectFlag = "Y";
                    materialName = $(this).parents("tr").find("td.materialName").text();
                    standard = $(this).parents("tr").find("td.standard").text();
                    material_code = $(this).parents("tr").find("td.material_code").text();
                    brand = $(this).parents("tr").find("td.brand").text();
                    standardUnit = $(this).parents("tr").find("td.standardUnit").text();
                    numCount = $(this).parents("tr").find("td.numCount").text();
                    return false;
                }
            });


           /* if(selectFlag=="N"){
                redragonJS.alert("必须选择一个采购订单");
            }else{
                $("#vendorName").val(supplier);
                $("#vendorContactDesc").val(contacts);
                $("#inputSourceHeadCode").val(deliveryCode);
                $("#inputSourceHeadName").val(deliveryName);
                $('#selectPODiv').modal('hide');
                $("#inputSourceType").val(deliveryMethod);
            }*/




            var html="";
            $("#InvInput").html("");
            html+="<tr>"
            html+="<th width='5%'>行号</th>"
            html+="<th>物料编码</th>"
            html+="<th>物料名称</th>"
            html+="<th>单位</th>"
            html+="<th>品牌</th>"
            html+="<th>规格型号</th>"
            html+="<th>库存数量</th>"
            html+="<th>出库数量</th>"
            html+="<th>费用归口</th>"
            html+="</tr>"


            html+="<tr>"
            html+="<td>"+0+"</td>"
            html+="<td id='material_code'>"+material_code+"</td>"
            html+="<td id='materialName'>"+materialName+"</td>"
            html+="<td id='standardUnit'>"+standardUnit+"</td>"
            html+="<td id='brand'>"+brand+"</td>"
            html+="<td id='standard'>"+standard+"</td>"
            html+="<td id='numCount'>"+numCount+"</td>"
            html+="<td><input type='text' style='width: 50%' value='"+0+"'></td>"
            html+="<td><input id='costSubject' type='text' style='width: 50%' value='' onclick='selCostSubject()'></td>"



           /* html+="<td><input id="+'invNum'+(i+1)+" type='text' style='width: 50%' value='"+0+"'></td>"
            html+="<td><input id="+'invLoss'+(i+1)+" type='text' style='width: 50%' value='"+0+"'></td>"
            html+="<td><input id="+'invGive'+(i+1)+" type='text' style='width: 50%' value='"+0+"'></td>"
            html+="<td><input id="+'invattachedMemo'+(i+1)+" type='text' style='width: 50%' value='"+0+"'></td>"*/
            html+="</tr>"
            $("#InvInput").append(html);
          /*  if($("#lineTab table tbody tr").length>0){
                redragonJS.alert("选择前必须删除所有行信息");
            }else{
                var selectFlag = "N"
                var deliveryCode =  "";
                var deliveryName = "";
                var supplier = "";
                var contacts = "";
                var deliveryMethod = "";

                $('.i-checks').each(function(){
                    if($(this).prop("checked")){
                        selectFlag = "Y";
                        deliveryCode = $(this).parents("tr").find("td.deliveryCode").text();
                        deliveryName = $(this).parents("tr").find("td.deliveryName").text();
                        supplier = $(this).parents("tr").find("td.supplier").text();
                        contacts = $(this).parents("tr").find("td.contacts").text();
                        deliveryMethod = $(this).parents("tr").find("td.deliveryMethod").text();
                        return false;
                    }
                });

                if(selectFlag=="N"){
                    redragonJS.alert("必须选择一个采购订单");
                }else{
                    $("#vendorName").val(supplier);
                    $("#vendorContactDesc").val(contacts);
                    $("#inputSourceHeadCode").val(deliveryCode);
                    $("#inputSourceHeadName").val(deliveryName);
                    $('#selectPODiv').modal('hide');
                    $("#inputSourceType").val(deliveryMethod);
                }
            } */
            $('#selectPODiv').modal('hide');
        });
    });

    function selCostSubject() {
        alert("zhege");
        $('#approverSelectOutput').modal('show');
        $('.show').removeClass("modal-backdrop");


        cost();
    }



    function cost() {

        var element_id1 = "";
        //jstree单击事件
        var selectedNodeId1 = -1;
        function clickJsTree(nodeId){
            selectedNodeId1 = nodeId;
            var selectText1 =  $("#jstree_div_output").jstree(true).get_text(selectedNodeId1);
            $('#'+element_id1).val(selectText1);
            $('#outPutDiv').modal('hide');
        }
        function dblclickJsTree(nodeId){
            if(selectedNodeId1!=nodeId){
                selectedNodeId1 = nodeId;
                var selectText1 =  $("#jstree_div_output").jstree(true).get_text(selectedNodeId1);
                $('#'+element_id1).val(selectText1);
                $('#outPutDiv').modal('hide');
            }
        }
        //默认jstree选择
        function stateReadyJsTree(nodeId){
            selectedNodeId1 = nodeId;
        }
        function close() {
            $("#outPutDiv").modal('hide').removeClass("show");
        }
    }





    //跳转页面
    function gotoPage(page){
        var pageNumber = ${requestScope.pages.pageNumber};
        var currentPage = ${requestScope.pages.page};
        //首页和尾页无需跳转
        if((currentPage==1&&page==1)||(currentPage==pageNumber&&page==pageNumber)){

        }else{
            getSelectOutputModal(page);
        }
    }
</script>
<script>
    $('#jstree_div_output').jstree({
        'core' : {
            "themes" : {
                "stripes" : false,//背景是否显示间纹
                "dots": false,//是否显示树连接线
                "icons": true,//是否显示节点的图标
                "ellipsis": true,//节点名过长时是否显示省略号
            },
            'multiple' : false,  // 可否多选
            'dblclick_toggle': true,   //允许tree的双击展开
            'expand_selected_onload': false,
            'data' : {
                'url': 'web/mdFinanceSubject/getMdFinanceSubjectTreeData',
                'dataType': 'json',
                'data': function (node) { // 传给服务端点击的节点
                    return { 'nodeId': node.id };
                },
                success: function (data) {

                    if(data.id==""){
                        $("#jstree_div_output").html("");
                    }else{
                        $("#addRootButton").hide();
                    }
                }
            },
            "check_callback" : true,
        },
        'plugins': ["state",'types','themes','search','unique','changed'],
        "types" : {
            "default" : {
                'icon' : 'fa fa-folder'
            },
            "root" : {
                "icon" : 'fa fa-home fa-lg',
            },
            "node" : {
                'icon' : 'fa fa-folder'
            },
        },
        'checkbox': {
            // 去除checkbox插件的默认效果
            'tie_selection': false,
            'keep_selected_style': true,
            'whole_node': false,
            'three_state': false,
        }
    })
    //单击事件
        .on('click.jstree', function(event) {
            /*getRelateListAjax1(getTreeSelectNodeId());*/
        })


    //设置查询功能
    var to = false;
    $('#searchTree1').keyup(function() {
        if (to) {
            clearTimeout(to);
        }
        to = setTimeout(function() {
            var v = $('#searchTree1').val();
            $('#jstree_div_output').jstree(true).search(v);
        }, 250);
    })
    //返回选择的节点id
    function getTreeSelectNodeId(){
        var selectId = $("#jstree_div_output").jstree(true).get_selected();
        return selectId.toString();
    }
    //返回选择的节点type
    function getTreeSelectNodeType1(){
        return $("#jstree_div_output").jstree(true).get_type(getTreeSelectNodeId());
    }



    function getRelateListAjax1(id){

        $.ajax({
            type: "post",
            url: "web/invOutputHead/getMdSubject",
            data: {"subjectId": id},
            async: false,
            dataType: "json",
            cache: false,
            success: function(data){
              alert();
              /*  alert(data.segmentDesc);
                if(data!=""){
                   /!* $("#relateListDiv").html(data);*!/
                    if(data.code==0){
                        data.segmentDesc
                        alert(data.segmentDesc);
                    }
                }*/
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }


    function submitSelect2() {
        var id = getTreeSelectNodeId();

        $.ajax({
            type: "post",
            url: "web/invOutputHead/getMdSubject",
            data: {"subjectId": id},
            async: false,
            dataType: "json",
            cache: false,
            success: function(data){
                if(data.code == 0){
                    $("#costSubject").val(data.segmentDesc);
                }
                $("#approverSelectOutput").modal('hide').removeClass("show");

            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

</script>